package com.yingjia.yingjiauniversity.utils;

import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.Environment;

import java.io.File;
import java.util.ArrayList;

/**
 * Created by lianhailiang on 2017/12/7.
 */

public class EmailManager {

    private static EmailManager instance;

    private EmailManager() {

    }

    public static EmailManager getInstance() {
        if (instance == null) {
            instance = new EmailManager();
        }
        return instance;
    }


    /**
     * \Mydmo_log\debug.log      \Mydmo_log\info.log
     * \Mydmo_log\all.log     \Mydmo_log\error.log   \Mydmo_log\crash.log
     * <p>
     * 很简单，发送邮件中，有收件者，抄送者，密送者。 也就是分别通过下面字段来进行putExtra来设定的
     * Intent.EXTRA_EMAIL, //收件者  Intent.EXTRA_CC, //抄送者     Intent.EXTRA_BCC  //密送者
     * 将日志发送到我的邮箱
     */
    public void SendLogMessage(Context context) {
        Intent intent = new Intent(Intent.ACTION_SEND_MULTIPLE);
        ArrayList imageUris = new ArrayList<Uri>();
        intent.setType("application/octet-stream");
        String sd_Path = Environment.getExternalStorageDirectory().getAbsolutePath();
        imageUris.add(Uri.fromFile(new File(sd_Path + "/MyDemo/logs/error.log")));
        imageUris.add(Uri.fromFile(new File(sd_Path + "/MyDemo/logs/crash.log")));
        intent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, imageUris);
        intent.putExtra(Intent.EXTRA_EMAIL, new String[]{"18817311356@163.com"});//收件人
        //intent_log.putExtra(Intent.EXTRA_CC, new String[]{"yl754980640@163.com"});//抄送者
        intent.putExtra(Intent.EXTRA_SUBJECT, "客户手机里面的错误日志"); //主题
//        intent.putExtra(Intent.EXTRA_TEXT, "日志上传:我的电话号码是" + getMyData().getMobile() + ",赢家App中用户id是" + getMyData().getUserid());//邮件内容
        intent.createChooser(intent, "选择应用");
        context.startActivity(intent);
    }


}
